var res;
function getData(){
    $.get('./php/show.php',function(data){
        res = JSON.parse(data);
    });
}
getData();
$('#refresh').click(function(){
    location.reload();
})

$('#reset').click(function(){
    $.get('./php/reset.php',function(data){
        alert('重置完成，可以开始新一轮测试！');
        location.reload();
    });
});

require.config({
    paths: {
        echarts: 'http://echarts.baidu.com/build/dist'
    }
});

require(
    [
        'echarts',
        'echarts/chart/bar',
    ],
    function(ec){
        var myChart = ec.init(document.getElementById('chart_bar'));

        var option = {
            tooltip : {
                show: true
            },
            calculable : true,
            legend: {
                data: ['耗时'],
            },
            xAxis: [
                {
                    type: 'value',
                    name : '耗时',
                    axisLabel : {
                        formatter: "{value} 秒"
                    }
                }
            ],
            yAxis: [
                {
                    type: 'category',
                    data : res.name
                }
            ],
            series: [
                {
                    'name' : '耗时',
                    'type' : 'bar',
                    'data' : res.time
                }
            ]
        };
        myChart.setOption(option);
    }
)

require(
    [
        'echarts',
        'echarts/chart/line'
    ],
    function(ec){
        var myChart = ec.init(document.getElementById('chart_line'));

        var option = {
            tooltip : {
                show: true
            },
            calculable : true,
            legend: {
                data: ['错误次数'],
            },
            xAxis: [
                {
                    type: 'value',
                    name: '错误次数',
                    axisLabel: {
                        formatter: "{value} 次"
                    }
                }
            ],
            yAxis: [
                {
                    type: 'category',
                    data : res.name
                }
            ],
            series: [
                {
                    "name" : "错误次数",
                    'type' : 'line',
                    'data' : res.num
                }
            ]
        };
        myChart.setOption(option);
    }
)